package com.ruoyi.web.controller.tableSettings;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.system.util.StoreIdUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TableManagement;
import com.ruoyi.system.service.ITableManagementService;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 桌台管理Controller
 *
 * @author ruoyi
 * @date 2025-05-07
 */
@Api(tags="桌台管理")
@RestController
@RequestMapping("/system/tableManagement")
public class TableManagementController extends BaseController
{
    @Autowired
    private ITableManagementService tableManagementService;

    @Autowired
    private StoreIdUtils storeIdUtils;

    /**
     * 查询桌台管理列表
     */
    @ApiOperation("查询桌台管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam(required = false) String storeName)
    {
        startPage();
        List<TableManagement> list = tableManagementService.selectTableManagementListByName(storeName);
        return getDataTable(list);
    }

    /**
     * 导出桌台管理列表
     */
    @ApiOperation("导出桌台管理列表")
    @PreAuthorize("@ss.hasPermi('system:management:export')")
    @Log(title = "桌台管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam(required = false) String storeName)
    {
        List<TableManagement> list = tableManagementService.selectTableManagementListByName(storeName);
        ExcelUtil<TableManagement> util = new ExcelUtil<TableManagement>(TableManagement.class);
        util.exportExcel(response, list, "桌台管理数据");
    }

    /**
     * 通过id获取桌台管理详细信息
     */
    @ApiOperation("通过id获取桌台管理详细信息")
    @PreAuthorize("@ss.hasPermi('system:management:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tableManagementService.selectTableManagementById(id));
    }

    /**
     * 新增桌台管理
     */
    @ApiOperation("新增桌台管理")
    @PreAuthorize("@ss.hasPermi('system:management:add')")
    @Log(title = "桌台管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TableManagement tableManagement)
    {
//        tableManagement.setStoreId(storeIdUtils.getStoreId());
        return toAjax(tableManagementService.insertTableManagement(tableManagement));
    }

    /**
     * 修改桌台管理
     */
    @ApiOperation("修改桌台管理")
    @PreAuthorize("@ss.hasPermi('system:management:edit')")
    @Log(title = "桌台管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TableManagement tableManagement)
    {
//        tableManagement.setStoreId(storeIdUtils.getStoreId());
        return toAjax(tableManagementService.updateTableManagement(tableManagement));
    }

    /**
     * 通过id批量删除桌台管理信息
     */
    @ApiOperation("通过id批量删除桌台管理信息")
    @PreAuthorize("@ss.hasPermi('system:management:remove')")
    @Log(title = "桌台管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tableManagementService.deleteTableManagementByIds(ids));
    }
}
